<?php
class Customer_Widgets_Evaluation_Widget extends Tomato_Widget
{
    protected function _prepareShow()
    {
        $user_id = $this->_request->getParam('user_id');
        $this->_view->assign('user_id', $user_id);

        /**
        * Get connection to database
        **/
        $conn = Tomato_Db_Connection::factory()->getMasterConnection();

        /**
        * Enterprise User model access to db
        */
        $userAccountDao = Tomato_Model_Dao_Factory::getInstance()->setModule('enterprise')->getUserDao();
        $userAccountDao->setDbConnection($conn);

        /**
         * Evaluation models access to data
        **/
        $customerDao = Tomato_Model_Dao_Factory::getInstance()->setModule('customer')->getCustomerDao();
        $customerDao->setDbConnection($conn);

        /**
        * Enterprise model access to db
        */
        $enterpriseDao = Tomato_Model_Dao_Factory::getInstance()->setModule('enterprise')->getEnterpriseDao();
        $enterpriseDao->setDbConnection($conn);


        /**
        * Check customer belong enterprise
        */
        $enterprise_id = null;
        $userAccount = $userAccountDao->getByUser($user_id);
        if($userAccount){
            $enterprise_id = $userAccount->enterprise_id;
        }

        /**
         * Check is enterprise or user
        **/
        $isEnterprise = false;
        $exp_id       = null;
        if($enterprise_id){
            /**
            * Get point and counter
            **/
            $avergePC = $enterpriseDao->getById($enterprise_id);
            $exp_id = $enterprise_id;
            $isEnterprise = true;
        }
        else{
            /**
            * Get point and counter
            **/
            $avergePC = $customerDao->getById($user_id);
            $exp_id = $user_id;
        }
        $this->_view->assign('avergePC', $avergePC);
        $this->_view->assign('exp_id', $exp_id);
        $this->_view->assign('isEnterprise', $isEnterprise);
    }
}
